#{extends 'common/supervisor.html' /}
#{set title:'站内信模板' /} 
<!-- 内容区域 -->
<div class="xn_c_contentwarp">
  <div class="xn_c_contentlist">
  <!--左-->
  #{include "supervisor/webContentManager/common/leftBar.control"/}
  <!--右-->
  <div class="xn_c_content">
  <div class="xf_ht_tablelist">
    <!-- 搜索 -->
    <div class="xf_ht_search">
    #{form @supervisor.webContentManager.TemplateAction.stationTemplates(), id:'stationSubmit'}
      <input type="hidden" name="id" id="stationId">
      <input type="hidden" name="currPage" id="currPage" value="${page?.conditions?.currPage}">
      <input type="hidden" name="pageSize" id="pageSize" value="${page?.conditions?.pageSize}">
      <div class="xf_ht_search_l">
		<span class="xf_sea_isshow" id="div_0"><a id="tab_0"  onclick="javascript:window.location.href='@{supervisor.webContentManager.TemplateAction.stationTemplates}'">系统模板</a></span>
		<span id="div_1"><a class="xn_c_li_title_a" id="tab_1"  onclick="javascript:window.location.href='@{supervisor.webContentManager.TemplateAction.myStationTemplates}'">自定义模板</a></span>
      </div>
     </div>
    <div class="xf_ht_search_inon">
       <div class="xf_ht_search_r">
         <div class="xf_ht_search_xl">
           <select id="type" class="xfht_t_j_td_1" name="type" value="${page?.conditions?.type}">
		     <option value="1">标题</option>
			 <option value="2" #{if page.conditions.type==2} selected="selected"#{/if}>内容</option>
		   </select>
         </div>
         <div class="xf_ht_search_xl">
           <input name="keyword" id="keyword" type="text"  class="search_w" title="请输入关键词" value="${page?.conditions?.keyword}"/>
         </div>
         <div class="xf_ht_search_xl">
           <input type="submit" class="search_button" value="搜索">
         </div>
       </div>
     </div>
    <!-- 列表内容 -->
    <div class="xn_c_content_top">
      #{table border:"0", cellspacing:"0", cellpadding:"0", class:"xn_c_content_list",tr_class_odd:"xn_tr_bj"}
        #{tr}
          #{th}序号#{/th}
          #{th}标题#{/th}
          #{th}内容#{/th}
          #{th}大小(KB)#{/th}
          #{th}应用场景#{/th}
          #{th}创建时间#{/th}
		  #{th}操作#{/th}
        #{/tr}
		#{list page.page}
        #{tr tr_index:_index}
          #{td}${(page?.currPage - 1)*page?.pageSize + _index}#{/td}
          #{td}${_?.title}#{/td}
          #{td}${_?.content?.substring(0, Math.min(_?.content?.length(), 20)) + "..."}#{/td}
          #{td}${_?.size}#{/td}
          #{td}${_?.title}#{/td}
		  #{td}${_?.time?.format("yyyy-MM-dd")}#{/td}
          #{td}
            <span class="xf_ta_onclick" onClick="previewTemplate(${_?.id});">浏览</span>
            <span class="xf_ta_onclick" onClick="editTemplate(${_?.id});">编辑</span>
            #{if _?.status == true}
              <span class="xf_ta_onclick" onClick="enable(${_?.id}, false);" id="enable${_?.id}">暂停</span>
			#{/if}
			#{else}
              <span class="xf_ta_onclick" onClick="enable(${_?.id}, true);" id="enable${_?.id}">启用</span>
			#{/else}
          #{/td}
        #{/tr}
		#{/list}
      #{/table}
    </div>
    <!-- 列表底部 -->
    <div class="xn_c_content_bottom">
      #{page currPage:page.currPage,pageSize:page.pageSize,totalCount:page.totalCount,theme:2,style:4}
	  #{/page}
    </div>
    </div>
    #{/form}
    </div>
  </div>
</div>
<!-- 浏览站内信模板-弹出层 -->
<div class="xf_ht_ttc" id="xf_ht_preview_ttc">
</div>
#{include "supervisor/webContentManager/TemplateAction/editStationTemplateInit.html"/}
<script type="text/javascript">
  #{if id == 0}
    $("#xf_ht_edit").hide();
  #{/if}
  #{else}
   showDiv($("#xf_ht_edit"));
   $("#hiddenshow").show();
  #{/else}

  $(function() {
    /* 高亮显示 */
    showHighLight(5,5,21);
  });
	
  function previewTemplate(id) {
    $.ajax({
      url : "@{previewStationTemplate()}",
      type : "POST",
      data : {
        "id" : id
      },
      success : function(data) {
        showDiv($("#xf_ht_preview_ttc").html(data));
        $.layer({
          type: 1,
          area: ['600', 'auto'],
          title: '浏览站内信模板',
          page: {dom : '#xf_ht_preview'}
        });
      },
      error : function() {
        alert("对不起，出现错误!");
      }
    });
  }
	
  function editTemplate(id) {
    $("#stationId").val(id);
    $("#currPage").val('${page?.currPage}');
    $("#stationSubmit").submit();
  }
	
  /**
    * 暂停/启用
    * @param id
    */
  function enable(id, status) {
    $.ajax({
      url : "@{updateStationTemplateStatus()}",
      type : "POST",
      data : {
        "id" : id,
        "status" : status
      },
      success : function(data) {
        if (data.code < 0) {
          alert(data.msg);
					
          return;
        }
			
        if (status) {
          $("#enable"+id).html("暂停");
	      $("#enable"+id).attr("href","javascript:enable("+id+", false)");
	      window.location.reload();
        } else {
          $("#enable"+id).html("启用");
          $("#enable"+id).attr("href","javascript:enable("+id+", true)");
          window.location.reload();
        }
      },
      error : function() {
        alert("对不起，出现错误!");
      }
    });
  }

  function showPage(currPage, pageSize){
    $("#currPage").val(currPage);
    $("#pageSize").val(pageSize);
    $("#stationSubmit").submit();
  }
</script>
